<!--  -->
<template>
  <div>
    <div v-if="form.kpiFillingNegativeLists.length != 0">
      <el-form ref="form" :model="form.kpiFillingNegativeLists[0]" label-width="400px" label-position="left">
        <el-form-item label="是否违反职业道德与行为规范" prop="moralityAndBehavior">
          <div style="display: flex;">
            <div style="margin-right: 100px;">
              <dict-tag :options="dict.type.sys_negative" :value="form.kpiFillingNegativeLists[0].moralityAndBehavior" />
            </div>
            <div>
              <el-radio-group v-model="form.kpiFillingNegativeLists[0].moralityAndBehavior" v-if="isShow">
                <el-radio v-for="dict in dict.type.sys_negative" :key="dict.value" :label="parseInt(dict.value)">
                  {{ dict.label }}
                </el-radio>
              </el-radio-group>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="是否违背国家相关法律法规言论" prop="speech">
          <div style="display: flex;">
            <div style="margin-right: 100px;">
              <dict-tag :options="dict.type.sys_negative" :value="form.kpiFillingNegativeLists[0].speech" />
            </div>
            <div>
              <el-radio-group v-model="form.kpiFillingNegativeLists[0].speech" v-if="isShow">
                <el-radio v-for="dict in dict.type.sys_negative" :key="dict.value" :label="parseInt(dict.value)">
                  {{ dict.label }}
                </el-radio>
              </el-radio-group>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="是否因学生评价极差，书记、校长信箱投诉" prop="complaint">
          <div style="display: flex;">
            <div style="margin-right: 100px;">
              <dict-tag :options="dict.type.sys_negative" :value="form.kpiFillingNegativeLists[0].complaint" />
            </div>
            <div>
              <el-radio-group v-model="form.kpiFillingNegativeLists[0].complaint" v-if="isShow">
                <el-radio v-for="dict in dict.type.sys_negative" :key="dict.value" :label="parseInt(dict.value)">
                  {{ dict.label }}
                </el-radio>
              </el-radio-group>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="是否因疏于教育、管理导致学生发生违纪违法" prop="offense">
          <div style="display: flex;">
            <div style="margin-right: 100px;">
              <dict-tag :options="dict.type.sys_negative" :value="form.kpiFillingNegativeLists[0].offense" />
              </div>
            <div>
              <el-radio-group v-model="form.kpiFillingNegativeLists[0].offense" v-if="isShow">
                <el-radio v-for="dict in dict.type.sys_negative" :key="dict.value" :label="parseInt(dict.value)">
                  {{ dict.label }}
                </el-radio>
              </el-radio-group>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="是否学生发生突发事件，未能及时到场处理" prop="emergency">
          <div style="display: flex;">
            <div style="margin-right: 100px;">
              <dict-tag :options="dict.type.sys_negative" :value="form.kpiFillingNegativeLists[0].emergency" />
            </div>
            <div>
              <el-radio-group v-model="form.kpiFillingNegativeLists[0].emergency" v-if="isShow">
                <el-radio v-for="dict in dict.type.sys_negative" :key="dict.value" :label="parseInt(dict.value)">
                  {{ dict.label  }}
                </el-radio>
              </el-radio-group>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="是否受到党纪、政纪处分" prop="punishment">
          <div style="display: flex;">
            <div style="margin-right: 100px;">
              <dict-tag :options="dict.type.sys_negative" :value="form.kpiFillingNegativeLists[0].punishment" />
            </div>
            <div>
              <el-radio-group v-model="form.kpiFillingNegativeLists[0].punishment" v-if="isShow">
                <el-radio v-for="dict in dict.type.sys_negative" :key="dict.value" :label="parseInt(dict.value)">
                  {{ dict.label }}
                </el-radio>
              </el-radio-group>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="是否在开展评优评奖等工作中弄虚作假的" prop="practiceFraud">
          <div style="display: flex;">
            <div style="margin-right: 100px;">
              <dict-tag :options="dict.type.sys_negative" :value="form.kpiFillingNegativeLists[0].practiceFraud" />
            </div>
            <div>
              <el-radio-group v-model="form.kpiFillingNegativeLists[0].practiceFraud" v-if="isShow">
                <el-radio v-for="dict in dict.type.sys_negative" :key="dict.value" :label="parseInt(dict.value)">
                  {{ dict.label }}
                </el-radio>
              </el-radio-group>
            </div>
          </div>


        </el-form-item>
      </el-form>
      <div class="button" v-if="form.kpiFillingNegativeLists[0].hasOwnProperty('id') && !(form.auditStatus === 1 && form.roleAudit === 4)">
        <el-button type="primary" v-show="isShow" @click="save">保 存</el-button>
        <el-button type="warning" @click="switchIsShow" v-if="!roleGroup.includes('辅导员') && audit">修 改</el-button>
      </div>
    </div>
    <div v-else>
      <h2>负面清单</h2>
      <div style="text-align: center;">暂无填写</div>
    </div>
  </div>
</template>

<script>
import { getKpiFillingNegativeList, updateKpiFillingNegativeList } from "@/api/teacher/kpiFillingNegativeList";
export default {
  dicts: ['sys_negative'],
  props: {
    form: {
      type: Object,
      default: []
    },
    roleGroup: {
      type: String,
      default: ""
    },
    audit: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      isShow: false
    }
  },
  watch: {
    "form.kpiFillingNegativeLists": {
      immediate: true,
      handler() {
        this.isShow = false
        // if (this.form.kpiFillingNegativeLists.length === 0) {
        //   this.form.kpiFillingNegativeLists[0] = {
        //     // moralityAndBehavior: 0,
        //     // offense: 0,
        //     // emergency: 0,
        //     // punishment: 0,
        //     // practiceFraud: 0
        //   }
        // }
      }
    }
  },
  methods: {
    switchIsShow() {
      this.isShow = !this.isShow
    },
    save() {
      this.$modal.loading('正在努力加载中，请稍等。。。')
      updateKpiFillingNegativeList(this.form.kpiFillingNegativeLists[0]).then(response => {
        // this.$modal.msgSuccess("修改成功");
        getKpiFillingNegativeList(this.form.kpiFillingNegativeLists[0].id).then(response => {
          this.form.kpiFillingNegativeLists[0].moralityAndBehavior = response.data.moralityAndBehavior,
          this.form.kpiFillingNegativeLists[0].moralityAndBehavioroffense = response.data.offense,
          this.form.kpiFillingNegativeLists[0].moralityAndBehavioremergency = response.data.emergency,
          this.form.kpiFillingNegativeLists[0].moralityAndBehaviorpunishment = response.data.punishment,
          this.form.kpiFillingNegativeLists[0].moralityAndBehaviorpracticeFraud = response.data.practiceFraud,
          this.$modal.msgSuccess("修改成功");
          this.switchIsShow()
          this.$modal.closeLoading()
        });
      });
    }
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {

  },
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {

  },
  // 离开当前页面时执行代码
  destroyed() {

  }
}
</script>
<style scoped>
/* @import url(); 引入css类 */
.button {
  margin-top: 20px;
  position: sticky;
  bottom: 0;
  background-color: white;
  z-index: 100;
  text-align: right;
  padding: 10px;
}
</style>
